<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>配置X-Pack的Java客户端 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'setup-xpack-client.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/setup-xpack-client.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/setup-xpack-client.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/setup-xpack-client.html" rel="nofollow" target="_blank">../en/setup-xpack-client.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="setup.html">安装和设置</a></span>
»
<span class="breadcrumb-node">配置X-Pack的Java客户端</span>
</div>
<div class="navheader">
<span class="prev">
<a href="setup-xpack.html">« 安装X-Pack</a>
</span>
<span class="next">
<a href="modules-plugins.html">插件 »</a>
</span>
</div>
<div class="chapter xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="setup-xpack-client"></a>配置X-Pack的Java客户端
</h2>
</div></div></div>
<div class="warning admon">
<div class="icon"></div>
<div class="admon_content">
<h3>在 7.0.0 版本中废弃。</h3>
<p>
<code class="literal">TransportClient</code> 已被废弃，取而代之的是<a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.7/java-rest-high.html" class="ulink" target="_top">Java 高级 REST 客户端</a>，并将在 Elasticsearch 8.0 中被移除。

<a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.7/java-rest-high-level-migration.html" class="ulink" target="_top">迁移指南</a> 描述了迁移所需的所有步骤。
</p>
</div>
</div>
<p>
如果您想在安装了 X-Pack 的集群上使用 Java <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api/7.7/transport-client.html" class="ulink" target="_top">传输客户端</a>，那么你必须下载并配置X-Pack传输客户端。
</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
将 X-Pack transport JAR 文件添加到 <span class="strong strong"><strong>CLASSPATH</strong></span> 中。

你可以下载 X-Pack 发行版并手动提取 JAR 文件，也可以从  <a href="https://artifacts.elastic.co/maven/org/elasticsearch/client/x-pack-transport/7.7.1/x-pack-transport-7.7.1.jar" class="ulink" target="_top">Elasticsearch Maven 仓库</a> 中获取。

与任何依赖项一样，你也需要它的可传递依赖项。

下载供离线使用时，请参考 <a href="https://artifacts.elastic.co/maven/org/elasticsearch/client/x-pack-transport/7.7.1/x-pack-transport-7.7.1.pom" class="ulink" target="_top">对应你的版本的 X-Pack POM 文件</a>。
</li>
<li class="listitem">
<p>
如果你使用的是 Maven，那么需要将 X-Pack JAR 文件作为一个依赖项添加到项目的 <code class="literal">pom.xml</code> 文件中:
</p>
<div class="pre_wrapper lang-xml">
<pre class="programlisting prettyprint lang-xml">&lt;project ...&gt;
     &lt;repositories&gt;
     &lt;!-- add the elasticsearch repo --&gt;
      &lt;repository&gt;
         &lt;id&gt;elasticsearch-releases&lt;/id&gt;
         &lt;url&gt;https://artifacts.elastic.co/maven&lt;/url&gt;
         &lt;releases&gt;
          &lt;enabled&gt;true&lt;/enabled&gt;
         &lt;/releases&gt;
         &lt;snapshots&gt;
            &lt;enabled&gt;false&lt;/enabled&gt;
         &lt;/snapshots&gt;
      &lt;/repository&gt;
      ...
   &lt;/repositories&gt;
   ...

   &lt;dependencies&gt;
      &lt;!-- add the x-pack jar as a dependency --&gt;
      &lt;dependency&gt;
         &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
         &lt;artifactId&gt;x-pack-transport&lt;/artifactId&gt;
              &lt;version&gt;{version}&lt;/version&gt;
      &lt;/dependency&gt;
      ...
   &lt;/dependencies&gt;
   ...

&lt;/project&gt;</pre>
</div>
</li>
<li class="listitem">
<p>
如果你使用的是 Gradle，你需要将 X-Pack JAR 文件作为一个依赖项添加到 <code class="literal">build.gradle</code> 文件中:
</p>
<div class="pre_wrapper lang-groovy">
<pre class="programlisting prettyprint lang-groovy">repositories {
  /* ... Any other repositories ... */

  // Add the Elasticsearch Maven Repository
  maven {
    name "elastic"
    url "https://artifacts.elastic.co/maven"
  }
}

dependencies {
  compile "org.elasticsearch.client:x-pack-transport:{version}"

  /* ... */
}</pre>
</div>
</li>
<li class="listitem">
<p>
如果你在公司内使用 <a href="https://www.sonatype.com/nexus-repository-oss" class="ulink" target="_top">Nexus OSS</a> 等存储库管理器，你需要按照下面的屏幕截图添加存储库:
</p>
<div class="imageblock">
<div class="content">
<a class="image" href="../static/security/images/nexus.png" rel="nofollow"><img src="../static/security/images/nexus.png" alt="Adding the Elastic repo in Nexus"></a>
</div>
</div>
<p>
然后，如果使用 maven，在项目的 <code class="literal">pom.xml</code> 中添加以下存储库和依赖项定义：
</p>
<div class="pre_wrapper lang-xml">
<pre class="programlisting prettyprint lang-xml">&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.elasticsearch.client&lt;/groupId&gt;
        &lt;artifactId&gt;x-pack-transport&lt;/artifactId&gt;
        &lt;version&gt;{version}&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;repositories&gt;
    &lt;repository&gt;
        &lt;id&gt;local-nexus&lt;/id&gt;
        &lt;name&gt;Elastic Local Nexus&lt;/name&gt;
        &lt;url&gt;http://0.0.0.0:8081/repository/elasticsearch/&lt;/url&gt;
        &lt;releases&gt;
            &lt;enabled&gt;true&lt;/enabled&gt;
        &lt;/releases&gt;
        &lt;snapshots&gt;
            &lt;enabled&gt;false&lt;/enabled&gt;
        &lt;/snapshots&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;</pre>
</div>
</li>
<li class="listitem">
如果你使用了 Elastic Stack 的安全功能，还有更多的配置步骤。
参考 <a href="java-clients.html" class="ulink" target="_top">Java 客户端和安全</a>。
</li>
</ol>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="setup-xpack.html">« 安装X-Pack</a>
</span>
<span class="next">
<a href="modules-plugins.html">插件 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>